<?php
/**
 * 
 *
 * @package    urCronPlugin
 * @subpackage urCronServiceYoutubeFavoritesPlugin
 * @author     Marc Weistroff <marc.weistroff@gmail.com>
 * @version    $Id: urCronServiceYoutubeFavorites.class.php 5 2009-06-09 09:15:55Z flambeur $
 */

class urCronServiceYoutubeFavorites extends urCronServiceBase
{
  public function __construct()
  {
    Zend_Feed::registerNamespace('openSearch', 'http://a9.com/-/spec/opensearchrss/1.0/');
    Zend_Feed::registerNamespace('gml', "http://www.opengis.net/gml");
    Zend_Feed::registerNamespace('georss', "http://www.georss.org/georss");
    Zend_Feed::registerNamespace('batch', 'http://schemas.google.com/gdata/batch');
    Zend_Feed::registerNamespace('yt', 'http://gdata.youtube.com/schemas/2007');
    Zend_Feed::registerNamespace('gd', 'http://schemas.google.com/g/2005');
    Zend_Feed::registerNamespace('media', 'http://search.yahoo.com/mrss/');
  }

  public function doCronJobAtom()
  {
    foreach($this->feed->entry as $entry)
    {
      if(Doctrine::getTable('UrCronItem')->fetchOneByOriginalId($entry->id()))
        return;

      $entryDom = $entry->getDOM();
      $object = new urCronItem();

      $publishedDate = date('Y-m-d H:i:s', strtotime($entry->published()));
      $data = array('original_id'                   => $entry->id(),
                    'original_content'              => $entry->content(),
                    'title'                         => $entry->title(),
                    'original_title'                => $entry->title(),
                    'ur_cron_feed_id'               => $this->feedId,
                    'original_published_date'       => $publishedDate,
                    'original_link'                 => $entry->link('alternate'),
                    'original_author'               => $entry->author->name(),
                    'ur_cron_feed_id'               => $this->feedId,
                    );

      $object->synchronizeWithArray($data);
      $object->addData( 'author_uri',    $entry->author->uri() );
      $object->addData( 'player_uri',    str_replace('?v=', '/v/', $entry->link('alternate')) . '&hl=en&fs=1');

      $object->save();
    }
  }
    
}
?>
